<script setup lang="ts">
import { PageProps } from '@/hooks/usePage'
import { messagePageAPI, messageReadBatchAPI } from '@/api/message'
import Item from './components/zanORcommentItme.vue'
import send from '@/components/forumList/components/send.vue'
const page = reactive<PageProps>({
    params: {
        bizTab: 3 // 业务tab：1.系统通知 2.服务通知 3.评论 4.新粉丝 5.赞/收藏
    },
    fetchData: messagePageAPI
})
const MeScrollPageREF = ref()
const sendObj = reactive({
    sendType: '1', // 评论类型  1. 产品 2,视频 3.帖子
    sendBindId: ''
})

const bindListObj = {
    600: '点赞了你的产品',
    601: '点赞了你的店铺',
    602: '点赞了你的视频',
    603: '点赞了你的帖子',
    700: '收藏了你的产品',
    701: '收藏了你的店铺',
    702: '收藏了你的视频',
    703: '收藏了你的帖子',
    100: '订单',
    200: '服务协议更新',
    300: 'U币变动',
    301: '购买会员',
    400: '评论了你的产品',
    401: '评论了你的视频',
    403: '评论了你的帖子',
    500: '用户粉丝'
}
const getData = () => {
    MeScrollPageREF.value.resetData()
}
const sendRef = ref()

// 回复
const recoverFn = (item: any) => {
    console.log(item)
    sendObj.sendType = item.commentType + ''
    sendObj.sendBindId = item.bindId
    isShowSend.value = true
    nextTick(() => {
        sendRef.value.focusFn({
            id: item.commentId, // 评论id
            userNickname: item.nickname
        })
    })
}

const isShowSend = ref(false)
const sendfinish = () => {
    isShowSend.value = false
}

//批量已读评论
const batchRead = () => {
    messageReadBatchAPI({
        type: [4],
        ids: (page.data as any[]).map((item: any) => item.id)
    })
}
</script>

<template>
    <view>
        <wxTopStatus backgroundColor="#fff">
            <view class="nav-title">评论</view>
        </wxTopStatus>
        <MeScrollPage type="body" ref="MeScrollPageREF" :page="page" @onGetListLafer="batchRead">
            <Item
                @getData="getData"
                @recover="recoverFn"
                :data="page.data"
                :bindListObj="bindListObj"
            ></Item>
        </MeScrollPage>
        <send
            v-show="isShowSend"
            ref="sendRef"
            @reGetData="sendfinish"
            :type="sendObj.sendType"
            :bindId="sendObj.sendBindId"
        ></send>
    </view>
</template>

<style scoped lang="scss"></style>
